package com.shop.record.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shop.record.dao.RecordMapper;
import com.shop.record.pojo.RecordInfo;
import com.shop.record.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @PackgeName: com.shop.record.service
 * @ClassName: t_storage_recordServiceimpl
 * @Author: 比巴卜
 * Date: 2021/7/23 10:18
 * project name: shop
 * @Version: 1.8
 * @Description:
 */
@Service
public class RecordServiceimpl implements RecordService {
    @Autowired
    private RecordMapper mapper;

    /**
     * 分页模糊查询
     *
     * @param deptno
     * @param pageNum 分页起始下标
     * @return
     */
    @Override
    public PageInfo<RecordInfo> FySelect(Integer deptno, Integer pageNum) {
        //保存当前页和每页显示的记录数
        PageHelper.startPage(pageNum, 3);
        Map<String, Object> map = new HashMap<>();
        map.put("deptno", deptno);
        //调用dao层方法
        List<RecordInfo> mgrs = mapper.Page(map);
        //通过pageInfo的构造方法赋值
        PageInfo<RecordInfo> pageInfo = new PageInfo<>(mgrs);
        return pageInfo;
    }

    /**
     * 添加
     *
     * @param record
     * @return
     */
    @Override
    public int Insert(RecordInfo record) {
        return mapper.Insert(record);
    }

    /**
     * 修改
     *
     * @param record
     * @return
     */
    @Override
    public int Update(RecordInfo record) {
        return mapper.Update(record);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    public boolean Delete(Integer id) {
        int delete = mapper.Delete(id);
        if (delete > 0) {
            return true;
        }
        return false;
    }
}
